package com.sam;

import java.util.Arrays;
import java.util.Enumeration;
import java.util.Vector;

public class VectorTest {

	public static void main(String[] args) {
		// Create Vector from Array
		Integer[] ary = {1, 2, 3, 4, 5};
		Vector<Integer> v = new Vector<Integer>(Arrays.asList(ary));
		
		// Add 100, 101, 102 to the head
		for (int i=100; i<=102; i++)
			v.insertElementAt(i, 0);
		
		// Add 200, 201, 202 to the tail
		for (int i=200; i<=202; i++)
			v.add(i);
		
		// Print out
		System.out.println(v);
		
		// Remove from collection
		Vector<Integer> v2 = new Vector<Integer>();
		
		for (int i=100; i<=102; i++)
			v2.add(i);
		v.removeAll(v2);
		
		System.out.println(v);
		
		// Test the capacity & size
		System.out.println("Capacity: " + v.capacity());
		System.out.println("Size: " + v.size());
		
		v.trimToSize();
		System.out.println("Capacity after trim: " + v.capacity());
		
		v.setSize(5);
		System.out.print("Set Size 5: ");
		System.out.println(v);
		
		// Get the [0], [2], [4] element
		System.out.println("Element [0], [2], [4]: " + v.get(0) + ", " + v.get(2) + ", " + v.get(4));
		
		// Set the [2] to 30
		v.set(2, 30);
		
		// Iterate the vector
		Enumeration<Integer> e = v.elements();
		while (e.hasMoreElements())
			System.out.print(e.nextElement() + " ");
		System.out.println();
		
		// Search for 30
		System.out.println("Contains 30? " + v.contains(30));
		System.out.println("Index of 30: " + v.indexOf(30));
		
		// Clone
		Vector<Integer> v3 = (Vector<Integer>) v.clone();
		v3.remove(new Integer(30));
		System.out.println("v3: " + v3);
		
		// Equals
		System.out.println("v == v3 ? " + v.equals(v3));
		
		// Retain v3 in v
		v.retainAll(v3);
		System.out.println("After retain v3: " + v);
		
	}
}
